package com.qa.service.impl;

import com.qa.constant.QuestionCategoryConstant;
import com.qa.entity.QuestionCategory;
import com.qa.mapper.QuestionCategoryMapper;
import com.qa.result.Result;
import com.qa.service.QuestionCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 徐
 */
@Service
public class QuestionCategoryServiceImpl implements QuestionCategoryService {

    @Autowired
    private QuestionCategoryMapper questionCategoryMapper;

    /**
     * 为题目设置分类
     *
     * @param questionCategory QuestionCategory
     * @return Boolean
     */
    @Override
    public Boolean setCategoryForQuestion(QuestionCategory questionCategory) {
        return questionCategoryMapper.setCategoryForQuestion(questionCategory) > 0;
    }

    /**
     * 删除该分类下的所有题目
     * <p/>
     * 即所有题目分类的联系（修改联系状态为不存在，题目依旧存在）
     *
     * @param categoryId 分类id
     * @return Integer
     */
    @Override
    public Result deleteQuestionsInCategory(Long categoryId) {
        Integer res = questionCategoryMapper.deleteQuestionsInCategory(categoryId);
        if (res < 1) {
            return Result.error(QuestionCategoryConstant.QUESTION_DELETE_FAILED);
        }
        return Result.success();
    }
}
